<template>
  <div>
    <!-- 表单填写 -->
    <div class="scrollbarTest">
      <Card style="margin-bottom:20px;">
        <Form ref="form" :model="form" :rules="rules" style="display: block;">
          <Row gutter="40">
            <i-col span="6">
              <FormItem>
                <Input v-model="form.contNo" placeholder="保单号" clearable />
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Input v-model="form.appntName" placeholder="投保人姓名" clearable />
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Select
                  v-model="form.payWay"
                  placeholder="交费方式"
                  @on-change="payWayChange"
                  clearable
                >
                  <Option
                    v-for="item in payWayList"
                    :key="item.key"
                    :value="item.key"
                  >{{item.value}}</Option>
                </Select>
              </FormItem>
            </i-col>
            <i-col span="6">
              <Row>
                <i-col span="11">
                  <FormItem>
                    <Input
                      placeholder="已交次数"
                      v-model="form.payCount"
                      :disabled="isDisabled"
                      clearable
                    />
                  </FormItem>
                </i-col>
                <i-col span="2" style="text-align:center;line-height:30px">-</i-col>
                <i-col span="11">
                  <FormItem>
                    <Select v-model="form.pay" clearable :disabled="isDisabled">
                      <Option
                        v-for="item in payList"
                        :key="item.key"
                        :value="item.key"
                      >{{item.value}}</Option>
                    </Select>
                  </FormItem>
                </i-col>
              </Row>
            </i-col>
          </Row>
          <Row gutter="40">
            <i-col span="6">
              <FormItem>
                <Select v-model="form.saleChannel" placeholder="销售渠道" clearable>
                  <Option
                    v-for="item in saleChannelList"
                    :key="item.key"
                    :value="item.key"
                  >{{item.value}}</Option>
                </Select>
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <DatePicker
                  type="daterange"
                  placeholder="签单时间段"
                  style="width:100%"
                  v-model="form.onDateChange"
                  :editable="false"
                  @on-change="dateChange"
                ></DatePicker>
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Select
                  v-model="form.payDifficult"
                  placeholder="交费难度"
                  clearable
                  :disabled="isDisabled"
                >
                  <Option v-for="(item,index) in 10" :key="index" :value="index">{{index}}级</Option>
                </Select>
              </FormItem>
            </i-col>
            <i-col span="6">
              <Row>
                <i-col span="11">
                  <FormItem prop="minFee">
                    <Input
                      placeholder="最低应收保费"
                      type="number"
                      v-model="form.minFee"
                      @on-blur="decimalConversion(form.minFee)"
                    />
                  </FormItem>
                </i-col>
                <i-col span="2" style="text-align:center;line-height:30px">-</i-col>
                <i-col span="11">
                  <FormItem prop="maxFee">
                    <Input
                      placeholder="最高应收保费"
                      type="number"
                      v-model="form.maxFee"
                      @on-blur="decimalConversion2(form.maxFee)"
                    />
                  </FormItem>
                </i-col>
              </Row>
            </i-col>
          </Row>
          <Row gutter="40">
            <i-col span="6">
              <FormItem>
                <Cascader change-on-select :data="organizationList" v-model="form.organization" placeholder="业务员机构" clearable ></Cascader>
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Input placeholder="业务员姓名" v-model="form.salesName" clearable />
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Cascader change-on-select :data="organizationList" v-model="form.reagentOrganization" @on-change="organizationChange" placeholder="续期专员机构" clearable></Cascader>
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Select
                  v-model="form.reagentName"
                  placeholder="续期专员姓名"
                  clearable
                  multiple
                  :disabled="isDisabled"
                >
                  <Option
                    v-for="item in reagentNameList"
                    :key="item.key"
                    :value="item.key"
                  >{{item.value}}-{{item.key}}</Option>
                </Select>
              </FormItem>
            </i-col>
          </Row>
          <Row gutter="40">
            <i-col span="6">
              <FormItem>
                <Select v-model="form.contMark" placeholder="保单标志" clearable :disabled="isDisabled">
                  <Option value="0">在职单</Option>
                  <Option value="1">孤儿单</Option>
                </Select>
              </FormItem>
            </i-col>
            <i-col span="6">
              <FormItem>
                <Select v-model="form.contStatus" placeholder="保单标志状态" clearable>
                  <Option
                    v-for="item in contStatusList"
                    :key="item.key"
                    :value="item.key"
                  >{{item.value}}</Option>
                </Select>
              </FormItem>
            </i-col>
          </Row>
          <Row gutter="40">
            <i-col span="12">
              <FormItem>
                <Button
                  type="primary"
                  style="margin-right:20px"
                  @click="handleSubmit(1)"
                  :loading="queryLoad"
                >查询</Button>
                <Button @click="handleReset()">重置</Button>
              </FormItem>
            </i-col>
          </Row>
        </Form>
      </Card>
    </div>
    <!-- 表格 -->
    <Card>
      <Row>
        <i-col span="24" style="margin-bottom:20px">
          <Button type="primary" @click="modalShow">
            <Icon type="md-flag" />发布交办件
          </Button>
        </i-col>
      </Row>
      <Table
        :columns="columns1"
        :data="data1"
        @on-select="selectSome"
        @on-select-cancel="selectSomeCancel"
        @on-select-all="selectAll"
        @on-select-all-cancel="selectAllCancel"
        @on-sort-change="sortChange"
      >
        <template slot="contno" slot-scope="{row}">
          <span style="color:rgba(24, 144, 255, 1)">{{row.contno}}</span>
        </template>
        <template slot-scope="{row}" slot="contstatename">
          <span v-if="row.contstatename == '有效'">
            <Button
              size="small"
              style="border-radius: 14px;background-color:rgb(24,144,255);color:#fff;padding-left:15px;padding-right:15px"
              @click="validDetail(row)"
            >有效</Button>
          </span>
          <span v-if="row.contstatename == '失效中'">
            <Button
              @click="validDetail(row)"
              size="small"
              style="border-radius:14px;width: 58px;padding-left:15px;padding-right:15px"
            >失效</Button>
          </span>
          <span v-if="row.contstatename == '已复效'">
            <Button
              @click="validDetail(row)"
              size="small"
              style="border-radius: 14px;background-color:rgb(67,207,124);color:#fff;padding-left:8px;padding-right:8px"
            >已复效</Button>
          </span>
          <span v-if="row.contstatename == '终止'">
            <Button
              @click="validDetail(row)"
              size="small"
              style="border-radius: 14px;background-color:rgb(255,141,26);color:#fff;padding-left:15px;padding-right:15px"
            >终止</Button>
          </span>
        </template>
        <template slot="payYear" slot-scope="{row}">
          <span v-if="row.payintvname === '趸交'">-</span>
          <span v-else-if="row.payYear == ''">-</span>
          <span v-else>{{row.payYear}}</span>
        </template>
        <template slot="difficulty" slot-scope="{row}">
          <span v-if="row.payintvname === '趸交'">-</span>
          <span v-else-if="row.difficulty == ''">-</span>
          <span v-else>{{row.difficulty}}</span>
        </template>
        <template slot="conttype" slot-scope="{row}">
          <span v-if="row.payintvname === '趸交'">-</span>
          <span v-else-if="row.conttype == ''">-</span>
          <span v-else>{{row.conttype}}</span>
        </template>
      </Table>
      <Page
        :total="total"
        show-sizer
        show-total
        style="text-align:right;margin-top:20px"
        @on-change="pageChange"
        @on-page-size-change="pageSizeChange"
        :page-size-opts="pageSizeOptions"
        :current="pageIndex"
        :page-size="pageSize"
        transfer
      ></Page>
    </Card>
    <!-- 发布交办件 -->
    <Modal
      footer-hide="true"
      :value="assignPlan"
      :mask-closable="false"
      @on-visible-change="modalVisibleChange"
      width="608"
    >
      <span slot="header" style="color:#fff;font-size:16px">发布交办件</span>
      <div style="width:85%">
        <Form ref="publishForm" :model="publishForm" :rules="publishRules" :label-width="100" style="display: block;">
          <FormItem label="保单号:" prop="contNo">
            <span class="assignSelect">
              <Select v-model="publishForm.contNo" placeholder="请选择" clearable multiple>
                <Option v-for="item in contNoList" :key="item" :value="item">{{item}}</Option>
              </Select>
            </span>
          </FormItem>
          <FormItem label="指派:" prop="casPeople">
            <Cascader
              change-on-select
              :data="cascaderData"
              trigger="hover"
              @on-change="casChange"
              v-model="publishForm.casPeople"
            ></Cascader>
          </FormItem>
          <FormItem label="工作方式:" prop="workType">
            <Select v-model="publishForm.workType" placeholder="请选择" clearable>
              <Option v-for="item in workTypeList" :key="item.key" :value="item.key">{{item.value}}</Option>
            </Select>
          </FormItem>
          <FormItem label="计划时间:" prop="planTime">
            <DatePicker
              placeholder="请选择日期"
              v-model="publishForm.planTime"
              :editable="false"
              style="width:100%"
            ></DatePicker>
          </FormItem>
          <FormItem label="备注:" prop="note">
            <span class="assignTextarea">
              <Input
                type="textarea"
                placeholder="请输入"
                v-model="publishForm.note"
                style="height:80px"
              />
            </span>
          </FormItem>
        </Form>
        <Row>
          <i-col span="24" style="text-align:right">
            <Button type="primary" @click="assignSubmit('publishForm')" :loading="assignLoading">确定</Button>
            <Button style="margin-left: 10px;margin-right:5px" @click="assignCancel('publishForm')">取消</Button>
          </i-col>
        </Row>
      </div>
    </Modal>
    <Button type="primary" @click="info" v-if="false"></Button>
    <div class="contain" ref="mybox" v-show="false">
      <canvas id="myCanvas" width="200" height="100" ref="myCanvas" style="position: absolute;"></canvas>
    </div>
  </div>
</template>

<script>
import util from "../../../util/util";
import {drawSign} from '../../../util/drawSign';
export default {
  data() {
    const validatePremium = (rule, value, callback) => {
      if (value) {
        let reg = /^[0-9][0-9]*$/;
        let reg1 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{1})$/;
        let reg2 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{2})$/;
        if (reg.test(value)) {
          callback();
        } else if (reg1.test(value)) {
          callback();
        } else if (reg2.test(value)) {
          callback();
        } else {
          callback(new Error("请输入两位小数"));
        }
      } else {
        callback();
      }
      callback();
    };
    return {
      form: {
        contNo: null,
        appntName: null,
        payWay: "1",
        payCount: null,
        pay: null,
        saleChannel: null,
        signRange: [],
        payDifficult: null,
        minFee: null,
        maxFee: null,
        organization: null,
        salesName: null,
        reagentOrganization: null,
        reagentName: [],
        contMark: null,
        contStatus: null,
        onDateChange: ["", ""]
      },
      // 下拉数据
      payWayList: [
        {
          key: "0",
          value: "趸交"
        },
        {
          key: "1",
          value: "期交"
        }
      ],
      payList: [],
      saleChannelList: [],
      organizationList: [],
      reagentOrganizationList: [],
      reagentNameList: [],
      contStatusList: [],
      rules: {
        minFee: [{ validator: validatePremium, trigger: "blur" }],
        maxFee: [{ validator: validatePremium, trigger: "blur" }]
      },
      // 表格数据
      columns1: [
        {
          type: "selection",
          align: "center",
          fixed: "left",
          width: 60
        },
        {
          title: "保单号",
          key: "contno",
          fixed: "left",
          width: 164,
          slot: "contno"
        },
        {
          title: "投保人",
          key: "appntname",
          align: "center",
          width: 120
        },
        {
          title: "交费方式",
          key: "payintvname",
          align: "center",
          width: 120
        },
        {
          title: "销售渠道",
          key: "salechnlname",
          align: "center",
          width: 120
        },
        {
          title: "主险",
          key: "mainRisk",
          minWidth: 240
        },
        {
          title: "总保费",
          key: "prem",
          sortable: true,
          sortable: "custom",
          width: 160
        },
        {
          title: "签单日期",
          key: "signdate",
          sortable: true,
          sortable: "custom",
          width: 150
        },
        {
          title: "已交次数",
          key: "payYear",
          align: "center",
          width: 100,
          slot: "payYear"
        },
        {
          title: "交费难度",
          key: "difficulty",
          align: "center",
          width: "120",
          width: 150,
          slot: "difficulty"
        },
        {
          title: "保单标志",
          key: "conttype",
          align: "center",
          width: 120,
          slot: "conttype"
        },
        {
          title: "保单状态",
          key: "contstatename",
          align: "center",
          width: 120,
          slot: "contstatename"
        }
      ],
      data1: [],
      total: 0,
      pageIndex: 1,
      pageSize: 10,
      pageSizeOptions: [5, 10, 15, 20],
      // 对话框数据
      assignPlan: false,
      // 发布交办件表单
      publishForm: {
        contNo: "",
        casPeople: [],
        workType: "",
        planTime: "",
        note: ""
      },
      publishRules: {
        casPeople: [
          {
            required: true,
            message: "指派人员不能为空"
          }
        ],
        planTime: [
          {
            required: true,
            message: "计划时间不能为空"
          }
        ]
      },
      contNoList: [],
      // 级联数据
      cascaderData: [],
      // 工作方式
      workTypeList: [],
      selection: [],
      selectLength: "",
      isDisabled: false,
      assignLoading: false,
      pageObj: "",
      queryLoad: false,
      result: "",
      historyObj: null,
      premorder: 0,
      paytodateorder: 0
    };
  },
  methods: {
    info(tip) {
      this.$Message.info(tip);
    },
    // 转化为两位小数
    decimalConversion(value) {
      let reg = /^[0-9][0-9]*$/;
      let reg1 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{1})$/;
      let reg2 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{2})$/;
      if (value) {
        if (reg.test(value)) {
          this.form.minFee = value + ".00";
        } else if (reg1.test(value)) {
          this.form.minFee = value + "0";
        } else if (reg2.test(value)) {
        } else {
          this.$refs.form.validateField("minFee");
        }
      } else {
        this.form.minFee = null;
      }
    },

    decimalConversion2(value) {
      let reg = /^[0-9][0-9]*$/;
      let reg1 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{1})$/;
      let reg2 = /^(([0-9]{1}\d*)|(0{1}))(\.\d{2})$/;
      if (value) {
        if (reg.test(value)) {
          this.form.maxFee = value + ".00";
        } else if (reg1.test(value)) {
          this.form.maxFee = value + "0";
        } else if (reg2.test(value)) {
        } else {
          this.$refs.form.validateField("maxFee");
        }
      } else {
        this.form.maxFee = null;
      }
    },
    dateChange(date) {
      this.form.onDateChange = date;
      // console.log(date)
    },
    // 重置
    handleReset() {
      this.form = {
        contNo: null,
        appntName: null,
        payWay: "1",
        payCount: null,
        pay: null,
        saleChannel: null,
        signRange: [],
        payDifficult: null,
        minFee: null,
        maxFee: null,
        organization: null,
        salesName: null,
        reagentOrganization: null,
        reagentName: [],
        contMark: null,
        contStatus: null,
        onDateChange: ["", ""]
      };
      this.isDisabled = false;
      this.queryLoad = false;
    },

    //表单---保单金额排序asc
    sortChange(column, key, order) {
      if (column.key == "signdate") {
        this.premorder = 0;
        // 应交日
        if (column.order == "asc") {
          // 升序
          this.paytodateorder = 1;
        } else if (column.order == "desc") {
          // 降序
          this.paytodateorder = 2;
        } else {
          // 默认
          this.paytodateorder = 0;
        }
      }
      if (column.key == "prem") {
        this.paytodateorder = 0;
        // 应收保费
        if (column.order == "asc") {
          // 升序
          this.premorder = 1;
        } else if (column.order == "desc") {
          // 降序
          this.premorder = 2;
        } else {
          // 默认
          this.premorder = 0;
        }
      }

      this.handleSubmit(999);
      // console.log(column, key, order);
    },

    // 提交表单
    handleSubmit(index) {
      
      if(index){
        this.pageIndex = index
      }
      
      this.$refs.form.validate(valid => {
        if (valid) {
          
          // if (util.formNullValidate(this.form)) {
          //   this.$Message.info("至少选择一个条件");
          //   // this.data1 = [];
          //   // this.total = 0;
          //   return;
          // }
          if (index != 1000) {
            this.queryLoad = true;
          }
          let obj = {
            agentcom: this.form.organization ? this.form.organization[this.form.organization.length-1] : "", //业务员机构
            agentname: this.form.salesName, //业务员姓名
            appntname: this.form.appntName, //投保人姓名
            contno: this.form.contNo, //保单号
            contstate: this.form.contStatus, //保单标志状态
            conttype1: null, //保单标志
            conttype2: null,
            difficulty: this.form.payDifficult, //交费难度
            index: this.pageIndex,
            pageSize: this.pageSize,
            payintv: null, //交费方式---期交分类多钟(标号)，趸交：0
            payintv1: null, //期交:1,趸交:null
            payyear: this.form.payCount, //交次
            reagentcom: this.form.reagentOrganization ? this.form.reagentOrganization[this.form.reagentOrganization.length-1] : "", //续期专员机构
            reagencodeList: this.form.reagentName + "", //续期专员姓名
            salechnl: this.form.saleChannel, //销售渠道
            minsigndate: this.form.onDateChange[0], //签单时间段(起)
            maxsigndate: this.form.onDateChange[1], //签单时间段(止)
            rangminprem: this.form.minFee, //最低保费
            rangmaxprem: this.form.maxFee, //最高保费
            premorder: this.premorder,
            paytodateorder: this.paytodateorder
          };
          for (let item in obj) {
            if (obj[item] == null || obj[item].length == 0) {
              delete obj[item];
            }
          }

          // conttype1:在职单，conttype2:孤儿单
          if (this.form.contMark == 1) {
            obj.conttype1 = 1;
          } else if (this.form.contMark == 0) {
            obj.conttype2 = 1;
          }
          if (this.form.payWay == 1) {
            obj.payintv1 = 1;
            obj.payintv = this.form.pay;
          } else if (this.form.payWay == 0) {
            obj.payintv = 0;
          }
          this.pageObj = obj;
          this.data1 = [];
          this.total = 0;
          console.log(obj,'111111111111111');
          this.api.selectUerlccont(obj).then(res => {
            if (res.code == 200 && res.data != null) {
              this.queryLoad = false;
              this.historyObj = null;
              if (index != 1000) {
                this.info(res.msg);
              }
              this.data1 = res.data.records;
              this.total = res.data.total;
              this.data1.forEach(element => {
                if (element.riskname && element.riskcode) {
                  element.mainRisk = element.riskname + "-" + element.riskcode;
                }
                if (
                  element.payyear &&
                  element.payyears &&
                  element.payintvname
                ) {
                  element.payYear =
                    element.payyear +
                    "/" +
                    element.payyears +
                    element.payintvname;
                }
              });
            } else {
              this.data1 = [];
              this.total = 0;
              this.info(res.msg);
            }
          });
        }else{
          console.log("没见来")
        }
      });
    },

    // 分页表单
    pageSubmit() {
      this.pageObj.index = this.pageIndex;
      this.pageObj.pageSize = this.pageSize;
      this.data1 = [];
      this.api.selectUerlccont(this.pageObj).then(res => {
        if (res.code == 200 && res.data != null) {
          this.data1 = res.data.records;
          this.total = res.data.total;
          this.data1.forEach(element => {
            if (element.riskname && element.riskcode) {
              element.mainRisk = element.riskname + "-" + element.riskcode;
            }
            if (element.payyear && element.payyears && element.payintvname) {
              element.payYear =
                element.payyear + "/" + element.payyears + element.payintvname;
            }
          });
        } else {
          this.data1 = [];
          this.total = 0;
          this.$Message.info(res.msg);
        }
      });
    },

    // 工作统计下拉框信息
    getProfessionalList() {
      this.api.professionalList().then(res => {
        if (res.code == 200 && res.data != null) {
          this.saleChannelList = res.data.salechnlListVOS;
          this.contStatusList = res.data.contstateListVOS;
          this.payList = res.data.payintvVOS;
        } else {
          this.contStatusList = [];
          this.saleChannelList = [];
          this.payList = [];
        }
      });
      //机构下拉框
      // this.api.selectUerList().then(res => {
      //   if (res.code == 200 && res.data != null) {
      //     this.organizationList = res.data[0].listKeyValueVOS;
      //   } else {
      //     this.organizationList = [];
      //   }
      // });
      // 续期机构下拉框
      // this.api.professionalList().then(res => {
      //   if (res.code == 200 && res.data != null) {
      //     if (res.data.listKeyValueVOS) {
      //       this.reagentOrganizationList = res.data.listKeyValueVOS;
      //     }
      //   } else {
      //     this.reagentorganizationList = [];
      //   }
      //   //console.log(res);
      // });
      return
      this.api.getBaseMapForHandoverInput().then(res => {
        if (res.code == 200 && res.data != null) {
          let a = res.data.establishmentshow;
          let b = [];
          let i = 0;
          a.forEach(element => {
            // upbranch为空 一级 86
            if (element.upbranch == null) {
              b[i] = {
                value: element.key,
                label: element.keyvalue,
                children: []
              };
              i++;
            } else {
              // upbranch不为空 二级 8601
              let j = 0;
              b.forEach(belement => {
                if (belement.value == element.upbranch) {
                  belement.children.push({
                    value: element.key,
                    label: element.keyvalue,
                    children: []
                  });
                } else {
                  // 三级 860101
                  belement.children.forEach(bchild => {
                    if (bchild && bchild.value == element.upbranch) {
                      bchild.children.push({
                        value: element.key,
                        label: element.keyvalue,
                        children: element.children
                      });
                      // 对flag等于1的进行循环，进入分部
                      bchild.children.forEach(bchildelement => {
                        if (bchildelement.children != null) {
                          bchildelement.children.forEach(detailelement => {
                            detailelement.label = detailelement.keyvalue;
                            detailelement.value = detailelement.key;
                            if (detailelement.children != null) {
                              detailelement.children.forEach(sonelement => {
                                sonelement.label = sonelement.keyvalue;
                                sonelement.value = sonelement.key;
                                if (sonelement.children != null) {
                                  sonelement.children.forEach(sunelement => {
                                    sunelement.label = sunelement.keyvalue;
                                    sunelement.value = sunelement.key;
                                    if (sunelement.children != null) {
                                      sunelement.children.forEach(
                                        zengsunelement => {
                                          zengsunelement.label =
                                            zengsunelement.keyvalue;
                                          zengsunelement.value =
                                            zengsunelement.key;
                                          zengsunelement.children = [];
                                        }
                                      );
                                    } else {
                                      sunelement.children = [];
                                    }
                                  });
                                } else {
                                  sonelement.children = [];
                                }
                              });
                            } else {
                              detailelement.children = [];
                            }
                          });
                        } else {
                          bchildelement.children = [];
                        }
                      });
                    }
                  });
                }
              });
            }
          });
          this.cascaderData = b;
          this.workTypeList = res.data.worktype;
        }
      });
    },

    // 根据管理机构查询员工
    organizationChange(value) {
      // console.log(value)
      if (!value) {
        this.reagentNameList = [];
      } else {
        $.ajax("scrm-gateway/scrm-uer/api/List/sekectreangencode/" + value[value.length-1], {
          method: "get",
          contentType: "application/json;charset=utf-8",
          headers: {
            Authorization: sessionStorage.getItem("credentials")
          },
          success: res => {
            if (res.code == 200 && res.data != null) {
              this.reagentNameList = res.data;
            } else {
              this.reagentNameList = [];
            }
          },
          error: res => {
            this.$Message.error(res.msg);
          }
        });
      }
    },

    // 分页设置
    pageChange(pageIndex) {
      this.pageIndex = pageIndex;
      this.pageSubmit();
    },
    pageSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.pageSubmit();
    },

    // 对话框
    modalShow() {
      this.assignPlan = true;
      this.contNoList = [];
      this.selection.forEach(element => {
        this.contNoList.push(element.contno);
      });
    },

    // 关闭弹出窗
    modalVisibleChange(boo) {
      if (boo == false) {
        this.assignPlan = false;
      }
      this.publishForm = {
        contNo: "",
        casPeople: [],
        workType: "",
        planTime: "",
        note: ""
      };
      this.$refs.publishForm.resetFields();
      this.publishForm.planTime = new Date()
    },

    // 级联值改变
    casChange(value, selectedData) {
      this.publishForm.casPeople = selectedData;
      // console.log(
      //   this.publishForm.casPeople[this.publishForm.casPeople.length - 1].key
      // );
    },

    assignCancel(name) {
      this.assignPlan = false;
      this.$refs[name].resetFields();
    },

    assignSubmit(name) {
      this.assignLoading = true;
      this.$refs[name].validate(valid => {
        if (valid) {
          let obj = {
            handOverContnos:
              this.publishForm.contNo.length > 0
                ? this.publishForm.contNo + ""
                : null,
            reagentcode: this.publishForm.casPeople[
              this.publishForm.casPeople.length - 1
            ].key
              ? this.publishForm.casPeople[
                  this.publishForm.casPeople.length - 1
                ].key
              : null,
            worktype:
              this.publishForm.workType == ""
                ? null
                : this.publishForm.workType,
            appointeddate: util.dateToISOString(this.publishForm.planTime),
            plandatetype: 2,
            remark: this.publishForm.note == "" ? null : this.publishForm.note,
            plantype: 3
          };

          this.api.saveplan(obj).then(res => {
            if (res.code == 200 && res.data != null) {
              this.$Message.info(res.msg);
            } else {
              this.$Message.info(res.msg);
            }
            this.assignLoading = false;
            this.$refs[name].resetFields();
            //20201216
            this.api.sendNotice({
              agentcode:obj.reagentcode, 
              contnos:res.data ? res.data.planid : obj.handOverContnos,
              // messageid:'',
              messagetype:'7'
            }).then(res2 => {
              console.log(res2)
            })
            this.api.pushOneUser({
              agentCode: obj.reagentcode,
              templateType: "6",
              // id: applyNo
              handOverCount: res.data ? res.data.handOverCount : 0
            }).then(res => {
              console.log(res)
            })
          });
        } else {
          this.assignLoading = false;
          this.$Message.error("输入信息有误");
        }
      });
    },

    // 进入有效无效详细页面
    validDetail(row) {
      sessionStorage.setItem("QUERYOBJ", JSON.stringify(this.pageObj));
      sessionStorage.setItem("QUERYFORM", JSON.stringify(this.form));
      sessionStorage.setItem("INSURANCE_TYPE3", "保单查询");
      this.$router.push({
        // name: "serviceDetail",
        // path: "serviceDetail",
        path: "/U/businessManagement/serviceDetail",
        query: {
          row: row,
          type: "policyEnquiry"
        }
      });
    },
    // 表格
    selectSome(selection, row) {
      this.selection = selection;
      this.selectLength = selection.length;
    },
    selectSomeCancel(selection, row) {
      this.selection = selection;
      this.selectLength = selection.length;
    },
    selectAll(selection) {
      this.selection = selection;
      this.selectLength = selection.length;
    },
    selectAllCancel(selection) {
      this.selection = selection;
      this.selectLength = selection.length;
    },
    // 交费方式改变
    payWayChange(value) {
      if (value == 0) {
        this.form.contNo = null;
        this.form.appntName = null;
        this.form.payCount = null;
        this.form.pay = null;
        this.form.saleChannel = null;
        this.form.signRange = [];
        this.form.payDifficult = null;
        this.form.minFee = null;
        this.form.maxFee = null;
        this.form.organization = null;
        this.form.salesName = null;
        this.form.reagentOrganization = null;
        this.form.reagentName = [];
        this.form.contMark = null;
        this.form.contStatus = null;
        this.form.onDateChange = ["", ""];
        this.isDisabled = true;
      }
      if (value == 1) {
        this.isDisabled = false;
      }
    },
    draw(ele,loginUser,loginTime) {
      let imageUrl = drawSign(ele,loginUser,loginTime)
      document.getElementsByClassName("ivu-table-fixed-body")[0].style.background = 'url(' + imageUrl + ') left top repeat'
      document.getElementsByClassName("ivu-table-fixed-body")[0].classList.add("add-background")
      document.getElementsByClassName("ivu-table-body")[0].style.background = 'url(' + imageUrl + ') left top repeat'
      document.getElementsByClassName("ivu-table-body")[0].classList.add("add-background")
    },
    getOrganization(){
      this.api.remanagecomList().then(res => {
        if (res.code == 200 && res.data != null) {
          let arr = []
          arr.push(res.data)
          arr.forEach(one=>{
            one.value = one.comcode
            one.label = one.comcode + '-' + one.name
            one.children = one.chilDren || []
            if (one.children) {
              one.chilDren.forEach(two=>{
                two.value = two.comcode
                two.label = two.comcode + '-' + two.name
                two.children = two.chilDren || []
                if (two.children) {
                  two.children.forEach(three=>{
                    three.value = three.comcode
                    three.label = three.comcode + '-' + three.name
                    three.children = three.chilDren || []
                    if (three.children) {
                      three.children.forEach(four=>{
                        four.value = four.comcode
                        four.label = four.comcode + '-' + four.name
                        four.children = four.chilDren || []
                      })
                    }
                  })
                }
              })
            }
          })
          console.log(arr);
          this.organizationList = arr
        } else {
          this.organizationList = [];
        }
      });
    }
  },
  mounted() {
    this.getOrganization()
    if (sessionStorage.getItem("INSURANCE_TYPE3") == "保单查询") {
      if (sessionStorage.getItem("QUERYOBJ")) {
        // 二次筛选条件
        this.historyObj = JSON.parse(sessionStorage.getItem("QUERYOBJ"));
        this.premorder = this.historyObj.premorder;
        this.paytodateorder = this.historyObj.paytodateorder;
        this.pageIndex = this.historyObj.index;
        this.pageSize = this.historyObj.pageSize;

        // 单次查询条件
        this.form = JSON.parse(sessionStorage.getItem("QUERYFORM"));
        this.form.onDateChange[0] = this.historyObj.minsigndate;
        this.form.onDateChange[1] = this.historyObj.maxsigndate;
        
        this.organizationChange(this.form.reagentOrganization);
        // console.log(this.historyObj, this.form);

        this.handleSubmit(1000);

        sessionStorage.removeItem("QUERYOBJ");
        sessionStorage.removeItem("QUERYFORM");
        sessionStorage.removeItem("INSURANCE_TYPE3");
      }
    }
    // 初始化下拉框
    this.getProfessionalList();
    let loginUser = sessionStorage.getItem("name");
    let loginTime =
    new Date().getFullYear() +
    "/" +
    (new Date().getMonth() + 1) +
    "/" +
    (new Date().getDate());
    this.draw(this.$refs.myCanvas,loginUser,loginTime)

  }
};
</script>

<style lang="less">
@import "./index";

.add-background td{
background-color: rgba(255,255,255,0) !important;
background: rgba(255,255,255,0) !important;
}
.assignTextarea > .ivu-input-wrapper > textarea {
  resize: none;
}
.assignTextarea > .ivu-input-wrapper > textarea.ivu-input {
  height: 80px;
}
.assignSelect > .ivu-select-multiple > .ivu-select-selection > div {
  height: 100px;
  overflow-y: scroll;
  -ms-overflow-style: none;
  overflow: -moz-scrollbars-none;
}
.assignSelect
  > .ivu-select-multiple
  > .ivu-select-selection
  > div::-webkit-scrollbar {
  display: none;
}
.scrollbarTest {
  scrollbar-arrow-color: #f4ae21; /*三角箭头的颜色*/
  scrollbar-face-color: #333; /*立体滚动条的颜色*/
  scrollbar-3dlight-color: #666; /*立体滚动条亮边的颜色*/
  scrollbar-highlight-color: #666; /*滚动条空白部分的颜色*/
  scrollbar-shadow-color: #999; /*立体滚动条阴影的颜色*/
  scrollbar-darkshadow-color: #666; /*立体滚动条强阴影的颜色*/
  scrollbar-track-color: #666; /*立体滚动条背景颜色*/
  scrollbar-base-color: #f8f8f8; /**/ /*滚动条的基本颜色*/
}
/* .scrollbarTest > .ivu-card {
  height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
} */
/*滚动条宽度设置：宽度为0 ，当有滚动条出现的时候则不显示滚动条*/
.scrollbarTest > ::-webkit-scrollbar {
  width: 7px;
}
.scrollbarTest > ::-webkit-scrollbar-thumb {
  background-color: #ccc;
  border-radius: 5px;
} /*滚动条滑块颜色设置*/
.scrollbarTest > ::-webkit-scrollbar-thumb:hover {
  background-color: #00aff0;
} /*滚动条滑块鼠标移上去颜色设置*/

.scrollbarTest > ::-webkit-scrollbar-thumb:active {
  background-color: #2d8cf0;
} /*滚动条鼠标点击颜色设置*/
</style>
